package com.qianxing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qianxing.po.TbNationLanguagePackPO;
import com.qianxing.service.TbNationLanguagePackService;
import com.qianxing.mapper.TbNationLanguagePackMapper;
import com.qianxing.vo.NationDataVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author JasonLong
 * @description 针对表【tb_nation_language_pack(民族方言语音包数据表)】的数据库操作Service实现
 * @createDate 2023-07-13 09:20:35
 */
@Service
public class TbNationLanguagePackServiceImpl extends ServiceImpl<TbNationLanguagePackMapper, TbNationLanguagePackPO>
        implements TbNationLanguagePackService {

    @Autowired
    private TbNationLanguagePackMapper nationLanguagePackMapper;

    /**
     * @param nationFlag
     * @return List
     * 该方法业务逻辑设计为：使用民族标记这个参数去数据库获取未被删除的对应民族的数据
     */
    @Override
    public List<NationDataVO> getNationLanguagePack(String nationFlag) {
        QueryWrapper<TbNationLanguagePackPO> wrapper = new QueryWrapper<>();
        //修改为模糊查询
        wrapper.like("nation_flag", nationFlag).eq("deleted", 0);
        return getListData(wrapper);
    }

    @Override
    public List<NationDataVO>  getNationDataByKeyword(String keyword, String nationFlag) {
        QueryWrapper<TbNationLanguagePackPO> wrapper = new QueryWrapper<>();
        wrapper.like("nation_translation", keyword).like("nation_flag", nationFlag).eq("deleted", 0);
        return getListData(wrapper);
    }

    @Override
    public List<NationDataVO>  getAll() {
        return getListData(null);
    }

    public List<NationDataVO> getListData(QueryWrapper<TbNationLanguagePackPO> wrapper) {
        List<NationDataVO> nationDataVOList = nationLanguagePackMapper.selectList(wrapper).stream().map(m -> {
            NationDataVO nationDataVO = new NationDataVO();
            nationDataVO.setNationVoiceurl(m.getNationVoiceurl());
            nationDataVO.setNationTranslation(m.getNationTranslation());
            nationDataVO.setIsplay(m.getIsplay());
            nationDataVO.setNationFlag(m.getNationFlag());
            return nationDataVO;
        }).collect(Collectors.toList());
        return nationDataVOList;
    }
}




